<template>
	<view class="search">
		<!-- <view class="lo_post">
			<view class="sign iconfont iconfont-e769"></view>
			<view class="title">{{ address || '定位中...' }}</view>
		</view> -->
		<u-search
			@search="confirm"
			@custom="confirm"
			@clear="confirm"
			height="54"
			:input-style="{ 'font-size': '12px' }"
			@click="goSearch"
			class="search_input"
			:placeholder="parameter.titlePlace || '请输入搜索内容'"
			v-model="searchVal"
			:disabled="parameter.relation?false:true"
			:show-action="parameter.relation && !parameter.sign?true:false"
		></u-search>
		<view v-if="parameter.sign" class="icon iconfont iconfont-e616" :style="{ color: parameter.signColor || 'inherit' }" @click="ProductSearch"></view>
	</view>
</template>

<script>
import { configMixin } from './configMixin.js';
import { authorize } from '@/utils/uniPromise.js';
export default {
	mixins: [configMixin],

	data() {
		return {
			searchVal: '',
			ref: '',
			dataList: [],
			address:''
		};
	},
	mounted() {
		// this.getLocation().then(res => {
		// 	this.getAddressName(res);
		// });
	},
	methods: {
		// 跳转搜索页
		goSearch() {
			if(!this.parameter.relation){
				this.$linkTo(`/package/product/prodSearch/productSearch`);
			}
		},
		// 关联搜索
		confirm (val) {
			this.$emit('relationSearch', { relation: this.parameter.relation, params: { [this.parameter.searchVal]: val || '' } });
		},
		ProductSearch() {
			uni.chooseImage({
				count: 1,
				success: res => {
					this.$linkTo(`/package/product/local/baiduSearch?resPath=${res.tempFilePaths[0]}`);
				}
			});
		},
		getLocation() {
			return new Promise((resolve,reject)=>{
				authorize('scope.userLocation')
					.then(() => {
						uni.getLocation({
							success: res => {
								resolve(res)
							},
							fail:()=>{
								reject()
							}
						});
					})
					.catch(() => {reject()});
			})
		},
		// 获取地址翻译
		getAddressName(res) {
			this.$resPost('CoordinateLocation',{
				coordinate_x:res.longitude,
				coordinate_y:res.latitude
			}).then(({data})=>{
				console.log('data',data)
				this.address = data.city
			})
		}
	}
};
</script>

<style scoped lang="scss">
.search {
	display: flex;
	align-items: center;
	padding: 16rpx 10rpx 16rpx 20rpx;
	/*  #ifdef  MP-ALIPAY */ 
	::v-deep .u-content{
		overflow:hidden !important;
	}
	/* #endif */
	.search_input {
		flex: 1;
		overflow: hidden;
		width: 100%;
		color: #999;
	}
	.icon {
		font-size: 46rpx;
		margin: 0 10rpx 0 20rpx;
	}
	.lo_post {
		display: flex;
		align-items: center;
		padding-right: 10rpx;
		.sign {
			margin-right: 6rpx;
			font-weight: bold;
			color: #fff;
		}
		.title {
			font-size: 30rpx;
			max-width: 460rpx;
			white-space: nowrap;
			overflow: hidden;
			text-overflow: ellipsis;
			color: #fff;
		}
		.you {
			font-size: 22rpx;
			margin-left: 6rpx;
			font-weight: bold;
			position: relative;
			top: 2rpx;
			color: #fff;
		}
	}
}
</style>
